package com.example.helloworld;

import java.util.ArrayList;
import java.util.Collections;

public class ArrayListAddDemo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Hello");
        list.add("World");
        System.out.println(list);
        System.out.println(list.get(1));
        list.set(1, "Java");
        System.out.println(list);
        list.remove(0);
        System.out.println(list);
        System.out.println(list.size());
        list.add(1, "Java");
        list.add(2, "Programming");
        list.add(3, "Language");
        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        // 使用forEach循环遍历ArrayList
        for(String s: list) {
            System.out.println(s);
        }

        // 字母排序
        Collections.sort(list);
        for(String s: list) {
            System.out.println(s);
        }


    }
}
